package com.woniu.service.impl;

import com.woniu.entity.AllUser;
import com.woniu.mapper.RegisterMapper;
import com.woniu.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author hq
 * @Date 2025/6/19$ 23:04$
 * @Description TODO
 * @Params $
 * @Return $
 **/
@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private RegisterMapper registerMapper;
    @Override
    public int add(AllUser allUser) {
        allUser.setCreateTime(new Date());
        allUser.setIsDelete("0");
        //默认角色为普通用户
        allUser.setRoleId(3);
        return registerMapper.insert(allUser);
    }
    //检查电话唯一性
    @Override
    public Boolean checkContact(String contact) {
        List<AllUser> allUsers = registerMapper.checkContact(contact);
        if (allUsers.size() == 0) {
            return true;
        }
        return false;
    }

    //检查用户名是否唯一
    @Override
    public Boolean checkUsername(String username) {
        List<AllUser> users =registerMapper.checkUsername(username);
        if (users.size() == 0) {
            return true;
        }
        return false;
    }
}
